package com.cangheng.app.testapp1.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cangheng.app.testapp1.dao.RawInDao;
import com.cangheng.app.testapp1.model.RawIn;

@Component
public class RawInDaoImpl implements RawInDao{

	@Autowired
	private SessionFactory sessionFactory;

	@Override
	@SuppressWarnings("unchecked")
	public List<RawIn> find () {
		return (List<RawIn>) this.getSessionFactory().getCurrentSession().createQuery("from RawIn").list();
	}

	@Override
	public Serializable save (RawIn rawIn) {
		return this.getSessionFactory().getCurrentSession().save(rawIn);
	}

	@Override
	public Serializable save1 () {
		RawIn rawIn = new RawIn();
		rawIn.setBatchInId(2);
		return this.getSessionFactory().getCurrentSession().save(rawIn);
	}

	@Override
	public void delete (RawIn rawIn) {
		this.getSessionFactory().getCurrentSession().delete(rawIn);
	}
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
}
